package cn.tangsihai.hrm.web.controller;

import cn.tangsihai.hrm.doc.CourseESDoc;
import cn.tangsihai.hrm.service.ICourseESService;
import cn.tangsihai.hrm.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/course")
public class CourseESController {
    @Autowired
    private ICourseESService courseESService;

    /**
     * 将课程添加到ES中
     * @param esDoc
     * @return
     */
    @PreAuthorize("hasAnyAuthority('es:saveCourse')")
    @PostMapping("/add")
    public AjaxResult addES(@RequestBody CourseESDoc esDoc){
        courseESService.addCourseToES(esDoc);
        return AjaxResult.me();
    }

    /**
     * 将课程从ES中删除
     * @param esDoc
     * @return
     */
    @PostMapping("/delete")
    public AjaxResult deleteCourseFromES(@RequestBody Long id){
        courseESService.deleteCourseFromES(id);
        return AjaxResult.me();
    }
}
